
package util;

/**
 * The implementation of the RouteTracker interface.
 * 
 * @version 5/3/2013
 * 
 */
public class RouteTrackerImpl implements RouteTracker
{

  /**
   * Total node number in the node.
   */
  private int my_total_node_number;

  /**
   * Constructor for this class.
   * 
   * @param the_total_node_number the total number of nodes in the ring.
   */
  public RouteTrackerImpl(final int the_total_node_number)
  {
    my_total_node_number = the_total_node_number;
  }

  /**
   * Getter for the my_total_node_number.
   * 
   * @return the total number of nodes in the ring.
   */
  public int getTotalNodeNumber()
  {
    return my_total_node_number;
  }

  /**
   * Set the total number of nodes in the ring.
   * 
   * @param the_total_node_number the total number of nodes in the ring.
   */
  public void setTotalNodeNumber(final int the_total_node_number)
  {
    my_total_node_number = the_total_node_number;
  }

  /**
   * Get the farthest node it can pass the message.
   * 
   * @param the_hash_value a hash value of the message to deliver.
   * @param the_node_id the id number of the node
   * @return the farthest node it can pass the message.
   */
  @Override
  public int getNextHop(final int the_hash_value, final int the_node_id)
  {
    final double pow = Math.pow(2, my_total_node_number);
    return (int) (the_node_id + pow);
  }

}
